package com.uhealin;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class TotalSaleMapper extends TableMapper<Text,DoubleWritable>{

	//private final IntWritable ONE = new IntWritable(1);
   	private Text text = new Text();
	
	@Override
	protected void map(ImmutableBytesWritable key, Result value,
			Mapper<ImmutableBytesWritable, Result, Text, DoubleWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO 자동 생성된 메소드 스텁
		String val = new String(value.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("saler_id")));
      	text.set(val);     // we can only emit Writables...
      	val = new String(value.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("amount")));
      	//value.getValue(Bytes.toBytes("cf"), Bytes.toBytes("amount"));
      	//IntWritable sales=new IntWritable();
        DoubleWritable amount=new DoubleWritable(Double.parseDouble(val));
    	context.write(text, amount);
		
	}

}
